package com.wei.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wei.model.ProductCategoryRelDO;
import com.wei.mapper.ProductCategoryRelMapper;
import com.wei.service.IProductCategoryRelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 产品分类关联表 服务实现类
 * </p>
 *
 * @author 蔡徐坤
 * @since 2025-07-28
 */
@Service
public class ProductCategoryRelServiceImpl extends ServiceImpl<ProductCategoryRelMapper, ProductCategoryRelDO> implements IProductCategoryRelService {


    @Override
    public List<Long> getProductIdsByCategoryId(Long categoryId) {
        LambdaQueryWrapper<ProductCategoryRelDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ProductCategoryRelDO::getCategoryId, categoryId);
        List<ProductCategoryRelDO> list = list(queryWrapper);

        return list.stream()
                .map(ProductCategoryRelDO::getProductId)
                .collect(Collectors.toList());
    }
}
